

#include "video_renderer_factory.h"




#include "opengles_video_renderer.h"


VideoRendererFactory::VideoRendererFactory()
{
}

VideoRendererFactory::~VideoRendererFactory()
{
}

VideoRendererFactory* VideoRendererFactory::getInstance()
{
    if (m_instance != nullptr) {
        return m_instance;
    }

    std::unique_lock<std::mutex> lock(m_instanceMutex);
    if (m_instance == nullptr) {
        m_instance = new VideoRendererFactory();
    }
    
    return m_instance;
}

void VideoRendererFactory::destroy()
{
    if (m_instance == nullptr) {
        return;
    }

    std::unique_lock<std::mutex> lock(m_instanceMutex);
    if (m_instance != nullptr) {
        delete m_instance;
        m_instance = nullptr;
    }
}


VideoRenderer* VideoRendererFactory::createRenderer(int type)
{
    VideoRenderer *renderer = nullptr;
    switch(type) {
        case 1:
            renderer = new OpenglesVideoRenderer();
            break;
        default:
            myLog("unknow renderer type, type:%d", type);
    }

    return renderer;
}
